{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 一、题目\n",
    "  定义两个字符串变量，str1 赋值为 “Hello”，str2 赋值为 “Python”。将这两个字符串拼接起来（中间加一个空格），并将结果存储在变量 greeting 中；  \n",
    "\n",
    "   计算 greeting 字符串的长度，存储在变量 length 中；获取 greeting 字符串的第一个字符，存储在变量 first_char 中。\n",
    "   最后一个字符存储在变量last_char中  \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " ## (1)拼接字符串 \n",
    "### 方法一：使用“+”运算符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello Python\n"
     ]
    }
   ],
   "source": [
    "str1 = 'Hello'\n",
    "str2 = 'Python'\n",
    "greeting = str1 + ' '+ str2\n",
    "print(greeting)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 方法二：使用f-string"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Hello Python\n"
     ]
    }
   ],
   "source": [
    "greeting1 = f'{str1} {str2}'\n",
    "print(greeting1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 方法三：join()方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "greeting2 = ' '.join([str1,str2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## (2)计算字符串长度和单个取出字符串里的字符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "字符串长度12\n",
      "第一个字符：H\n",
      "最后一个字符：n\n"
     ]
    }
   ],
   "source": [
    "length = len(greeting)\n",
    "first_char = greeting[0]\n",
    "last_char = greeting[-1]\n",
    "print(f'字符串长度{length}\\n第一个字符：{first_char}\\n最后一个字符：{last_char}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']\n"
     ]
    }
   ],
   "source": [
    "print(dir(\"hello\")) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 二、题目:\n",
    "定义两个整数变量，score_a 赋值为 75，score_b 赋值为 90。比较 score_a 是否大于 score_b，将比较结果（布尔值）存储在变量 is_a_higher 中；  \n",
    "比较 score_a 是否小于等于 score_b，将结果存储在变量 is_a_lower_or_equal 中；  \n",
    "比较 score_a 是否不等于 score_b，将结果存储在变量 is_different 中。然后，使用 f-string 分三行打印出类似以下格式的信息：  \n",
    "75 是否大于 90: False\n",
    "75 是否小于等于 90: True\n",
    "75 是否不等于 90: True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "75 是否大于 90:False\n",
      "75 是否小于等于90:True\n",
      "75 是否不等于90:True\n"
     ]
    }
   ],
   "source": [
    "score_a = 75\n",
    "score_b = 90\n",
    "is_a_higher = score_a > score_b\n",
    "is_a_lower_or_equal = score_a <= score_b\n",
    "is_different = score_a != score_b\n",
    "print(f'''{score_a} 是否大于 {score_b}:{is_a_higher}\n",
    "{score_a} 是否小于等于{score_b}:{is_a_lower_or_equal}\n",
    "{score_a} 是否不等于{score_b}:{is_different}''')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pylearn",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
